package com.datacollection.datacollectionsystem.webdriver;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.List;

@Configuration
@PropertySource("classpath:webdriver.properties")
public class DriverConfig {
    @Value("${chrome.driver.path}")
    private String chromeDriverPath;
    @Value("#{'${chrome.driver.options}'.split(',')}")
    private List<String> chromeArguments;

    @Bean(destroyMethod = "quit")
    public WebDriver chrome() {
        System.setProperty("webdriver.chrome.driver", chromeDriverPath);
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments(chromeArguments);
        return new ChromeDriver(chromeOptions);
    }
}
